﻿'========================================================================
'功能:群組人員管理
'作者:andy
'日期: 2011/2/8
'========================================================================

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Data.SqlClient
Imports System.Text
Imports System.Data
Partial Class WebForm_Manage_GroupMemberMaintain
    Inherits BasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            hiUID.Value = ActualUID
            hiDBName.Value = dbName
            lblTitle.Text = GetLocalResourceObject("lblTitle")

            If Not ChkProgramRight(1) Then '查詢
                gvUID.Visible = False
                ddlGroupID.Visible = False
            End If
            If Not ChkProgramRight(2) Then '編輯

                gvUID.Columns(0).Visible = False


            End If

            Dim groupBBL As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
            Dim dtGroup As DataTable = groupBBL.GetGroupIDdt(dbName)
            ddlGroupID.DataSource = dtGroup
            ddlGroupID.DataBind()

        End If

    End Sub

    Protected Sub ddlGroupID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlGroupID.SelectedIndexChanged
        gvUID.DataBind()
    End Sub

    Protected Sub gvUID_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvUID.RowUpdating
        Dim UID1 As String = CType(gvUID.Rows(e.RowIndex).FindControl("txtUID"), TextBox).Text

        If UID1 = "" Then
            e.Cancel = True
            ShowMessageForAjax(ddlGroupID, GetLocalResourceObject("errUIDEmpty"))

            Exit Sub

        End If

        Dim bl As OAMS.BBL.GroupBBL = New OAMS.BBL.GroupBBL()
        If bl.GroupMemberIsExist(ddlGroupID.SelectedValue, UID1, dbName) Then
            e.Cancel = True
            ShowMessageForAjax(ddlGroupID, GetLocalResourceObject("errUIDExist"))
            Exit Sub
        End If

        Dim uBBL As OAMS.BBL.UsersBBL = New OAMS.BBL.UsersBBL()
        If Not uBBL.UserIsExist(UID1, dbName) Then

            e.Cancel = True
            ShowMessageForAjax(ddlGroupID, GetLocalResourceObject("errUIDNotExist"))
            Exit Sub
        End If
        '不知什麼原因直接用gridview的功能無法新增資料到DB中(UID1為NULL),所以用程式
        bl.InsertGroupMember(ddlGroupID.SelectedValue, UID1, hiUID.Value, dbName)
        e.Cancel = True
        gvUID.EditIndex = -1
        gvUID.DataBind()
    End Sub

    Protected Sub btnUID_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim txtuid As TextBox = CType(gvUID.Rows(gvUID.EditIndex).FindControl("txtUID"), TextBox)
        PopupFormForAjax(gvUID, "emp_no,emp_name", GetLocalResourceObject("ChnFieldsName"), "Users", dbName, "1", txtuid.ClientID, "directories=no,location=no,menubar=no,toolbar=no,scrollbars=yes, width=500 ,left=200")


    End Sub
End Class
